#include "CalibParam.h"
#include "MainFrame.h"
#include <iostream>

using namespace std;
CalibParam::CalibParam( wxWindow* parent )
:
CalibParamTemplate( parent )
{
	char* value = new char[30];
	wxString wxValue;
	
		
	MainFrame* mainWindow = (MainFrame*) parent;
	
	double* params = mainWindow->getEtalonParams();
	char* dir = mainWindow->getImgDir();
	
	sprintf(value, "%f", params[0]);
	wxValue = wxValue.FromAscii(value);
	textCtrlNW->SetValue(wxValue);
	
	sprintf(value, "%f", params[1]);
	wxValue = wxValue.FromAscii(value);
	textCtrlNH->SetValue(wxValue);
	
	sprintf(value, "%f", params[2]);
	wxValue = wxValue.FromAscii(value);
	textCtrlSSS->SetValue(wxValue);
	
	wxValue = wxValue.FromAscii(dir);
	textCtrlDir->SetValue(wxValue);
	
	
	this->ShowModal();
	delete value;

}

void CalibParam::OnCancelClick( wxCommandEvent& event )
{
	this->EndModal(1);wxString value;
	
}

void CalibParam::onOkClick( wxCommandEvent& event )
{
	MainFrame* parent = (MainFrame*)this->GetParent();
	
	wxString value;
	char *dir = new char[100];
	
	double* params = new double[3];
	
	value = textCtrlNW->GetValue();
	params[0] = atof(value.char_str());
	
	
	value = textCtrlNH->GetValue();
	params[1] = atof(value.char_str());
	
	
	value = textCtrlSSS->GetValue();
	params[2] = atof(value.char_str());
	
	value = textCtrlDir->GetValue();
	//dir = value.char_str();
	sprintf(dir,value.char_str());
	
	parent->setEtalonParams(params);
	parent->setImgDir(dir);
	this->EndModal(1);
}
